package com.queclink.ycm.entity.data.useless;

import com.alibaba.fastjson.JSONObject;
import com.queclink.ycm.common.utils.HexUtils;
import com.queclink.ycm.entity.data.Data;
import com.queclink.ycm.entity.data.useless.Data81;

import java.text.DecimalFormat;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2021-12-27 14:10:00
 */
public class Data95 extends Data {

    private String Location;
    private String OverspeedTime;
    private String OverspeedMileage;
    private String MaxSpeed;

    public String getLocation(JSONObject jsonObject) {
        JSONObject location = jsonObject.getJSONObject("Location");
        Data81 data81 = new Data81();
        String s = data81.combine81(location);
        return s;
    }

    public String getOverspeedTime(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer overspeedTime = jsonObject.getInteger("OverspeedTime");
        String s = HexUtils.intToHex(overspeedTime, 4);
        sb.append(s);
        return sb.toString();
    }

    public String getOverspeedMileage(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer overspeedMileage = jsonObject.getInteger("OverspeedMileage");
        String s = HexUtils.intToHex(overspeedMileage, 4);
        sb.append(s);
        return sb.toString();
    }

    public String getMaxSpeed(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Double maxSpeed = jsonObject.getDouble("MaxSpeed");
        String format = new DecimalFormat("0.0").format(maxSpeed);
        String replace = format.replace(".", "");
        String s = HexUtils.intToHex(Integer.valueOf(replace), 4);
        sb.append(s);
        return sb.toString();
    }

    public String getDataID() {
        // data95
        return "5f";
    }

    public String getLength() {
        return "15";
    }

    @Override
    public String combine(JSONObject jsonObject) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getDataID());
        sb.append(this.getLength());
        sb.append(this.getLocation(jsonObject));
        sb.append(this.getOverspeedTime(jsonObject));
        sb.append(this.getOverspeedMileage(jsonObject));
        sb.append(this.getMaxSpeed(jsonObject));
        return sb.toString();
    }
}
